package com.atguigu.tingshu.album;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import io.minio.errors.MinioException;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * Author:huzhongkui
 * Date: 2025-01-14 星期二 11:42:22
 * Description:
 */
public class ApiTest {


    public static void main(String[] args) throws Exception {

//        minioTestApi1();

//        byte[] bytes = {1, 2, 3};  // 该对象的hashcode和下一个对象的hashcode不一样
//        byte[] bytes1 = {1, 2, 3};
//        System.out.println(String.valueOf(bytes)); // [B@de0a01f
//        System.out.println(String.valueOf(bytes1)); // [B@4c75cab9

//        byte[] bytes = {1, 2, 3};
//        byte[] bytes1 = {1, 2, 3};
//        String s="abc";
//        String s1="abc";
//        System.out.println(bytes);  // 
//        System.out.println(bytes1); // 


        String  s="1.png";
        System.out.println(s.substring(1,s.length())); // [1,4)

    }

    private static void minioTestApi1() throws InvalidKeyException, IOException, NoSuchAlgorithmException {
        try {
            // 1.创建minio客户端用于和minio进行通信
            MinioClient minioClient =
                    MinioClient.builder()
                            .endpoint("http://localhost:9000")  // minio服务器的地址在哪里
                            .credentials("admin", "admin123456")
                            .build();

            // 2.minio是否存在一个桶
            boolean found =
                    minioClient.bucketExists(BucketExistsArgs.builder().bucket("demo").build());
            if (!found) {

                minioClient.makeBucket(MakeBucketArgs.builder().bucket("demo").build());
            } else {
                System.out.println("Bucket demo already exists.");
            }
            // 上传逻辑（未来任何资源在minio眼中都就对象）
            minioClient.uploadObject(
                    UploadObjectArgs.builder()
                            .bucket("demo")
                            .object("2.png")
                            .filename("C:\\Users\\hzk\\Pictures\\3.png")
                            .build());
            System.out.println("文件对象上传成功");
        } catch (MinioException e) {

            System.out.println("文件对象上传失败");
        }
    }
}
